home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Taming the Mouse / EnterLeave / EnterLeave.cs next >
Encoding:
Text File  |  2001-01-15  |  1.1 KB  |  46 lines

  1. //-----------------------------------------
  2. // EnterLeave.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class EnterLeave: Form
  9. {
  10.      bool bInside = false;
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new EnterLeave());
  15.      }
  16.      public EnterLeave()
  17.      {
  18.           Text = "Enter/Leave";
  19.      }
  20.      protected override void OnMouseEnter(EventArgs ea)
  21.      {
  22.           bInside = true;
  23.           Invalidate();
  24.      }
  25.      protected override void OnMouseLeave(EventArgs ea)
  26.      {
  27.           bInside = false;
  28.           Invalidate();
  29.      }
  30.      protected override void OnMouseHover(EventArgs ea)
  31.      {
  32.           Graphics grfx = CreateGraphics();
  33.     
  34.           grfx.Clear(Color.Red);
  35.           System.Threading.Thread.Sleep(100);
  36.           grfx.Clear(Color.Green);
  37.           grfx.Dispose();
  38.      }
  39.      protected override void OnPaint(PaintEventArgs pea)
  40.      {
  41.           Graphics grfx = pea.Graphics;
  42.  
  43.           grfx.Clear(bInside ? Color.Green : BackColor);
  44.      }
  45. }
  46.